﻿using Asxsyd92Core.Utils;
using Asxsyd92Core.Utils.Provider;
using System;
using System.Linq;
using WebOS.Dal;

namespace WebOS.Bll
{
    public class CommonTaskBll
    {
        public static CommonTaskBll Instance
        {
            get { return SingletonProvider<CommonTaskBll>.Instance; }
        }

        public string WaitList(Guid guid, string title, Guid user, DateTime date1, DateTime date2, string desc, int page, int limit)
        {
            string counts = "(select count(1) from CommonTask where Status in(0,1) and SenderID='" + guid + "' ";
            string sqls = "", f = "";
            string sql = "";

            if (title != "" && title != null)
            {
                title = "'%" + title + "%'";
                sql = sql + " and Title like " + title;
                counts = counts + " and Title like " + title;
                f = f + " and Title like " + title;
            }

            //降序
            sql = sql + "and RowNumber > " + limit + " * (" + page + " - 1)";
            //分页
            var fy = "(SELECT ROW_NUMBER() OVER(ORDER BY " + desc + ") AS RowNumber,*FROM CommonTask where  Status in(0,1) and SenderID='" + guid + "' " + f + ")";
            sqls = "select top " + limit + "  *," + counts + ") as Count  from " + fy + " as A where  Status in(0,1) and SenderID='" + guid + "' " + sql;
            var da = CommonTaskDal.Instance.GetList(sqls, new { }).ToList();

            return JSONhelper.ToJson(new { code = 0, msg = "", count = da.Count == 0 ? 0 : da.First().Count, data = da }, false);
        }

    }
}
